package com.jnu.assistant.utils;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

public class JwtUtils {


    public static String generateJwt(Integer userId) {
        return Jwts.builder()
                .claim("userId",userId)
                .signWith(SignatureAlgorithm.HS256, "3r4s5t6u7v8w9x0y1z2a3b4c5d6e7f8g9h0i1j2k3l4m5n6o7p8q9r0s1t2u3v4w5x6y7z8a9b0")//签名算法（头部）
                .compact();
    }
    /**
     * 解析JWT令牌
     *
     * @param jwt JWT令牌
     * @return JWT第二部分负载 payload 中存储的内容
     */
    public static Claims parseJWT(String jwt) {
        return Jwts.parser()
                .setSigningKey("3r4s5t6u7v8w9x0y1z2a3b4c5d6e7f8g9h0i1j2k3l4m5n6o7p8q9r0s1t2u3v4w5x6y7z8a9b0")//指定签名密钥
                .parseClaimsJws(jwt)//指定令牌Token
                .getBody();
    }
}
